package com.cdyx.outsideprescription.util;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import sun.net.www.http.HttpClient;

import java.time.Instant;
@Slf4j
public class HttpUtils {
    public static HttpEntity getEntity(String s){
        HttpHeaders headers=new HttpHeaders();
        //随机字符串
        String nonce = UUIDUtils.getUUID();
        //当前时间戳
        long timestamp = Instant.now().getEpochSecond();
        String token = "1b0c989668594e0fa48ac91b90d39fbc";
        String paasid = "hsa_mbs_fsi";
        //价签结果
        String signature = "";
        try {
            signature = SHACoder.encodeSHA256Hex(StringUtils.join(timestamp, token, nonce, timestamp));
        } catch (Exception e) {
            e.printStackTrace();
        }
        MediaType mediaType = MediaType.parseMediaType("application/json;charset=UTF-8");
        headers.setContentType(mediaType);
        headers.set("x-tif-paasid", paasid);
        headers.set("x-tif-signature", signature);
        headers.set("x-tif-timestamp", String.valueOf(timestamp));
        headers.set("x-tif-nonce", nonce);
        log.info("============================>");
        log.info("头信息=====>"+headers);
        HttpEntity<String> formEntity=new HttpEntity<>(s,headers);
        return formEntity;
    }
}
